#include "prec_matrix.h"

#include "matrix.h"

const char *prec_name[5];

void init_prec_name()
{
  prec_name[EQ] = "=";
  prec_name[GT] = ">";
  prec_name[LT] = "<";
  prec_name[ND] = "?";
  prec_name[NOP] = "NoP";
}

void init_tex_prec_name()
{
  prec_name[EQ] = "$\\doteq$";
  prec_name[GT] = "$\\gtrdot$";
  prec_name[LT] = "$\\lessdot$";
  prec_name[ND] = " ";
  prec_name[NOP] = "NoP";
}

void print_matrix(parsing_ctx *ctx)
{
  uint32_t i, j;
  gr_token i_tok, j_tok;
  printf("Printing matrix\n%12s", "");
  for (i = 0; i < TERM_LEN; i++) {
    printf("%12s", ctx->gr_token_name[token_value(gr_term_token(i))]);
  }
  printf("\n");
  for (i = 0; i < TERM_LEN; i++) {
    i_tok = gr_term_token(i);
    printf("%11s:", ctx->gr_token_name[token_value(i_tok)]);
    for (j = 0; j < TERM_LEN; j++) {
      j_tok = gr_term_token(j);
      printf("%12s", prec_name[PRECEDENCE(ctx->matrix, i_tok, j_tok)]);
    }
    printf("\n");
  }
}

void print_tex_matrix(parsing_ctx *ctx)
{
  uint32_t i, j;
  gr_token i_tok, j_tok;
  printf("Printing matrix in TeX format\n");
  for (i = 0; i < TERM_LEN; i++) {
    printf("& %s ", ctx->gr_token_name[token_value(gr_term_token(i))]);
  }
  printf("\\\\\n");
  for (i = 0; i < TERM_LEN; i++) {
    i_tok = gr_term_token(i);
    printf("%s", ctx->gr_token_name[token_value(i_tok)]);
    for (j = 0; j < TERM_LEN; j++) {
      j_tok = gr_term_token(j);
      printf(" & %s", prec_name[PRECEDENCE(ctx->matrix, i_tok, j_tok)]);
    }
    printf(" \\\\\n");
  }
}

